package model.userModel;

import empty.users.Company;

import java.sql.SQLException;
import java.util.List;

public class CompanyModel {

    public int insert(Company company) throws SQLException{
        String sql = "INSERT INTO company (name, address, master, phone) VALUES (?, ?, ?, ?)";
        return Tool.DML(sql, company.getName(), company.getAddress(), company.getMaster(), company.getPhone());
    }

    public int delete(Company company) throws SQLException{
        String sql = "DELETE FROM company WHERE id = ?";
        return Tool.DML(sql, company.getId());
    }

    public int update(Company company) throws SQLException{
        String sql = "UPDATE company SET name = ?, address = ?, master = ?, phone = ? WHERE id = ?";
        return Tool.DML(sql, company.getName(), company.getAddress(), company.getMaster(), company.getPhone(), company.getId());
    }

    public List<Object []> findAll(Company company) throws SQLException{
        String sql = "SELECT * FROM company";
        return Tool.DQL(sql);
    }

    public List<Object []> findByName(Company company) throws SQLException{
        String sql = "SELECT * FROM company WHERE name = ?";
        return Tool.DQL(sql, company.getName());
    }

}
